<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <!-- 引入组件库 -->
        <script type="text/javascript" src="../js/jquery.min.js"></script>
        <script src="../js/vue.js"></script>
        <script src="../plugins/elementui/index.js"></script>
        <script src="../js/axios-0.18.0.js"></script>
        <style>
            .avatar-uploader .el-upload {
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
                position: relative;
                overflow: hidden;
            }
            .avatar-uploader .el-upload:hover {
                border-color: #409EFF;
            }
            .avatar-uploader-icon {
                font-size: 28px;
                color: #8c939d;
                width: 178px;
                height: 178px;
                line-height: 178px;
                text-align: center;
            }
            .avatar {
                width: 178px;
                height: 178px;
                display: block;
            }
            .datatable {
                position: relative;
                box-sizing: border-box;
                -webkit-box-flex: 1;
                width: 100%;
                max-width: 100%;
                font-size: 14px;
                color: rgb(96, 98, 102);
                overflow: hidden;
                flex: 1 1 0%;
            }
            .datatable td, .datatable th {
                padding: 12px 0;
                min-width: 0;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-overflow: ellipsis;
                vertical-align: middle;
                position: relative;
                text-align: left;
            }
        </style>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="预约日期/手机号码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="search()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="setmealId" align="center" label="预约项目"></el-table-column>
                        <el-table-column prop="date"   label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column label="性别" align="center">
                            <template slot-scope="scope">
                                <span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini">编辑</el-button>
                                <el-button size="mini" type="danger">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增电话预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form label-position="right" :model="formData" :rules="rules" label-width="100px" ref="dataAddForm">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="日期">
                                                        <el-date-picker v-model="formData.orderDate" type="datetime" placeholder="选择日期时间"></el-date-picker>
                                                        <!--<el-input v-model="formData.date" />-->
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="档案号" prop="fileNumber">
                                                        <el-input v-model="formData.fileNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="性别">
                                                        <el-select v-model="formData.sex">
                                                            <el-option label="不限" value="0"></el-option>
                                                            <el-option label="男" value="1"></el-option>
                                                            <el-option label="女" value="2"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号码">
                                                        <el-input v-model="formData.phoneNumber"></el-input>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="预约状态">
                                                        <!--<el-input v-model="formData.status" ></el-input>-->
                                                        <el-select v-model="formData.orderStatus">
                                                            <el-option label="已预约" value="0"></el-option>
                                                            <el-option label="已取消预约" value="1"></el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约项目" prop="setmealId">
                                                        <el-input v-model="formData.setmealId" ></el-input>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                   <!-- <el-tab-pane label="检查组信息" name="second">
										<div class="checkScrol">
											<table class="datatable">
												<thead>
												<tr>
													<th>选择</th>
													<th>项目编码</th>
													<th>项目名称</th>
													<th>项目说明</th>
												</tr>
												</thead>
												<tbody>
												<tr v-for="c in tableData">
													<td>
														<input :id="c.id" v-model="checkgroupIds" type="checkbox" :value="c.id">
													</td>
													<td><label :for="c.id">{{c.code}}</label></td>
													<td><label :for="c.id">{{c.name}}</label></td>
													<td><label :for="c.id">{{c.remark}}</label></td>
												</tr>
												</tbody>
											</table>
										</div>
                                    </el-tab-pane>-->
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加/编辑窗口Tab标签名称
                pagination: {//分页相关属性
                    currentPage: 1,
                    pageSize:10,
                    total:0,
                    queryString:null,
                },
                dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//控制添加窗口显示/隐藏
                dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
                rules: {//校验规则
                    fileNumber: [{ required: true, message: '档案号为必填项', trigger: 'blur' }],
                    name: [{ required: true, message: '姓名为必填项', trigger: 'blur' }],
                    setmealId:[{ required: true, message: '项目ID为必填项', trigger: 'blur' }]
                }
            },
            created() {
                this.findPage();
            },
            methods: {
                //查询方法
                search() {
                    this.pagination.currentPage = 1;
                    this.findPage();
                },
                //编辑
                handleEdit() {
                },
                //添加
                handleAdd () {

                    //表单校验
                    this.$refs['dataAddForm'].validate((flag)=>{
                        console.log(flag);

                        if (flag) {
                            //3.符合要求，则发送异步请求提交数据
                            axios.post("/order/addByPhone.do", this.formData).then((response) => {
                                //先打印一下响应数据
                                // console.log(response);
                                if (response.data.flag) {
                                    //隐藏新增窗口
                                    this.dialogFormVisible=false;
                                    //刷新页面加载数据
                                    this.findPage();
                                }
                                //显示给用户提示信息（不管成功失败都要提示）
                                this.$message({
                                    message:response.data.message,
                                    type:response.data.flag?'success':'error'
                                })
                            }).catch((error)=>{
                                //异步请求发生异常时的提示信息
                                this.$message.error("网络异常")
                            });
                        }else{
                            //表单校验失败
                            this.$message.error("表单数据校验失败");
                            return false;
                        }
                    });


                },
                //分页查询
                findPage() {
                    axios.post("/order/findPage.do",this.pagination).then((response)=>{
                        // console.log(response);
                        this.pagination.total=response.data.total;
                        this.dataList=response.data.rows;
                    })
                },
                // 重置表单
                resetForm() {
                    this.formData={}
                },
                // 弹出添加窗口
                handleCreate() {
                    //每次点击"新建"按钮：重置表单输入项，并且显示新增窗口
                    this.resetForm();
                    this.dialogFormVisible = true;
                },
                // 弹出编辑窗口
                handleUpdate(row) {
                    //根据id去后台查询要修改的数据，并回显
                    axios.get("/order/findById.do",{
                        //这样只是写法优雅一点，但是最终它会帮你把参数拼接在url后面
                        params:{
                            id:row.id
                        }
                    }).then((res)=>{
                        this.formData = res.data.data;

                        //并弹出编辑框
                        this.dialogFormVisible4Edit = true;
                    })
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    //1.删除需要谨慎处理，因此需要弹出框确认（then是确认，catch是取消）
                    this.$confirm('此操作将永久删除该检查项, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        //需要去数据库查询，判断该检查项是否被检查组引用，若被引用，则提示用户不能删除
                        axios.delete("/ordersettinglist/delete.do?id="+row.id).then((res)=>{
                            //如果成功刷新页面
                            if (res.data.flag) {
                                this.findPage();
                            }
                            //不管成功失败都提示用户信息
                            this.$message({
                                message:res.data.message,
                                type:res.data.flag?'success':'error'
                            })
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });

                }
            }
        })
    </script>
</html>
